'use strict';
const http = require('../utils/httpUtils');
const namespace = require('./namespace');
module.exports = function (app) {

  app.get(`${namespace.root}`, async function (req, res) {
    
    res.render('index', {
    });
  });

  app.get(`${namespace.root}/recommend_product`, async function (req, res) {
    
    res.render('recommend_product', {
    });
  });

  app.get(`${namespace.root}/market`, async function (req, res) {
    
    res.render('market', {

    });
  });

  app.get(`${namespace.root}/best`, async function (req, res) {
    
    res.render('best', {

    });
  });

  app.get(`${namespace.root}/special`, async function (req, res) {
    
    res.render('special', {

    });
  });

  app.get(`${namespace.root}/special_office`, async function (req, res) {
    
    res.render('special_office', {

    });
  });

  app.get(`${namespace.root}/follow`, async function (req, res) {
    
    res.render('follow', {

    });
  });

  app.get(`${namespace.root}/coll_zuji`, async function (req, res) {
    
    res.render('coll_zuji', {

    });
  });

  app.get(`${namespace.root}/coll_shop`, async function (req, res) {
    
    res.render('coll_shop', {

    });
  });

  app.get(`${namespace.root}/sp_last_antique`, async function (req, res) {
    
    res.render('sp_last_antique', {

    });
  });

  app.get(`${namespace.root}/release`, async function (req, res) {
    
    res.render('release', {

    });
  });

  app.get(`${namespace.root}/tpl_chat`, async function (req, res) {
    res.render('tpl_chat', {

    });
  });

  app.get(`${namespace.root}/my`, async function (req, res) {
    
    res.render('my', {

    });
  });
  app.get(`${namespace.root}/my_shop`, async function (req, res) {
      var jump = req.query.jump;
    res.render('my_shop', {
        jump: jump
    });
    
  });

  app.get(`${namespace.root}/chat`, async function (req, res) {
    var charToUser = req.query.charToUser;
    var productId = req.query.productId;
    let userId = charToUser.replace('hx_','');
    //查询聊天用户的详细信息
    let result = await http.get(`/api/sysUser/query_user_by_userId`, {
      userId: userId
    }, '/antique').catch(e => {
      res.send({
        errCode: 401
      });
    });
    res.render('chat', {
      charToUser: charToUser,
      productId:productId,
      userInfo:result.data
    });
  });

  //清除cookie信息
  app.get(`${namespace.root}/clearCookie`, async function (req, res) {
    res.cookie("name",'', { expires: new Date(0) });
    res.cookie("photo",'', { expires: new Date(0) });
    res.cookie("token", '', { expires: new Date(0) });
    res.cookie("unionid", '', { expires: new Date(0) });
    res.cookie("userId", '', { expires: new Date(0) });    
    res.json({
      code: 100,
      msg:'清除用户信息成功!' 
    });
  });

  //记录前端访问日志信息
  app.get(`${namespace.root}/log`, async function (req, res) {
    let info = req.query.info;
    if(info){
      console.log(info);
    }
  });

  app.get(`${namespace.root}/hot`, async function (req, res) {
    res.render('hot', {
    });
  });

  app.get(`${namespace.root}/post`, async function (req, res) {
    var id = req.query.id;
    res.render('post', {
      id:id
    });
  });

  app.get(`${namespace.root}/que_an`, async function (req, res) {
    res.render('que_an', {
    });
  });
};